Skip to content

Fix bug when gradle clean spotlessCheck was called on parallel build - #501

Merged
nedtwigg merged 3 commits into
masterfrom
feat/fix-parallel
Jan 1, 2020
Merged

nedtwigg merged 3 commits into
masterfrom
feat/fix-parallel

Conversation

@nedtwigg

@nedtwigg nedtwigg commented Dec 31, 2019 •

Copy link
Copy Markdown
Member

Fixes #243

@nedtwigg
nedtwigg merged commit 402be65 into master Jan 1, 2020
@nedtwigg
nedtwigg deleted the feat/fix-parallel branch January 1, 2020 00:29
// actually happen (as desired)
//
// we use System.identityHashCode() to avoid a memory leak by hanging on to the reference directly
SpotlessCache.clearOnce(System.identityHashCode(project.getRootProject()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nedtwigg Reading the source code for SpotlessCache::clearOnce, I'm unclear on why passing project.getRootProject() to the method would cause the method to hang onto it; AFAICT the method never stores the reference inside a field or something similar. 🤔

So I was wondering if you could help me understand why the call to System::identityHashCode is needed here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a better way to spell it, but I think the javadoc is the clearest explanation.

if (key == null || !key.equals(lastClear)) {
	lastClear = key;
} else {
	// only clear once
	return false;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, that lastClear = key line is what I'd missed! Thank you @nedtwigg. :)

@nedtwigg

nedtwigg commented Jan 2, 2020

Copy link
Copy Markdown
Member Author

Published in 3.27.0 (twitter announcement)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exceptions when running clean & spotlessCheck during same build with buildcache

2 participants